package cn.sany.cterminal.ctrl;

import cn.sany.cterminal.common.CommonReturn;
import cn.sany.cterminal.common.constants.CommonConst;
import cn.sany.cterminal.common.constants.CterminalConst;
import cn.sany.cterminal.entity.request.StatisticQueryParam;
import cn.sany.cterminal.service.RealtimeInfoService;
import cn.sany.cterminal.service.StatisticService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 *
 * @Project : sany
 * @Package : cn.sany.cterminal.ctrl
 * @Class : RealtimeInfoController
 * @Description : 实时信息接口
 * @author : zhouxing
 * @CreateDate : 2020-09-14 13:31:46
 * @version : V0.5
 * @Copyright : 2020 sany.com Inc. All rights reserved.
 * @Reviewed :
 * @UpateLog :    Name    Date    Reason/Contents
 *             ---------------------------------------
 *                ****    ****    ****
 *
 */
@RestController
@RequestMapping(path = "info")
@Slf4j
public class RealtimeInfoController {
    @Autowired(required = false)
    RealtimeInfoService realtimeInfoService;

    /**
     *
     * @Method : getElectricityConsum
     * @Description : 获取实时信息接口
     * @return : cn.sany.cterminal.common.CommonReturn
     * @author : zhouxing
     * @CreateDate : 2020-09-14 13:38:32
     *
     */
    @PostMapping(path = "getRealTimeInfo")
    public CommonReturn getRealTimeInfo() {
        log.info("访问getRealTimeInfo接口，获取实时信息接口");
        CommonReturn commonReturn = new CommonReturn();
        try{
            Map result = realtimeInfoService.getRealTimeInfo();
            commonReturn.setResultCode(CommonConst.SUCCESS_CODE);
            commonReturn.setResultMsg(CommonConst.SUCCESS_DESC);
            commonReturn.setData(result);
        }catch (Exception e){
            log.error("获取实时信息接口出错：",e);
            commonReturn.setResultCode(CommonConst.FAIL_CODE);
            commonReturn.setResultMsg(CommonConst.FAIL_DESC);
        }
       return commonReturn;
    }

    /**
     *
     * @Method : getDeviceLocation
     * @Description : 获取所有设备位置信息接口
     * @return : cn.sany.cterminal.common.CommonReturn
     * @author : zhouxing
     * @CreateDate : 2020-09-14 17:50:54
     *
     */
    @PostMapping(path = "getDeviceLocation")
    public CommonReturn getDeviceLocation() {
        log.info("访问getDeviceLocation接口，获取所有设备位置信息接口");
        CommonReturn commonReturn = new CommonReturn();
        try{
            List result = realtimeInfoService.getDeviceLocation();
            commonReturn.setResultCode(CommonConst.SUCCESS_CODE);
            commonReturn.setResultMsg(CommonConst.SUCCESS_DESC);
            commonReturn.setData(result);
        }catch (Exception e){
            log.error("获取所有设备位置信息接口出错：",e);
            commonReturn.setResultCode(CommonConst.FAIL_CODE);
            commonReturn.setResultMsg(CommonConst.FAIL_DESC);
        }
        return commonReturn;
    }
}
